/*
 * Problem.cpp
 *
 *  Created on: 20/06/2013
 *      Author: marcio
 */

#include "Problem.h"

Problem::Problem( long variables){
	rest = 0;
	var = variables;
	mtx = new Matrix<double>();
	b = new Vector<double>();
	obj = new Vector<double>();
	sense = new Vector<char>();
	ub = new Vector<double>();
	lb = new Vector<double>();
}

Problem::Problem(long variables, double* upb, double* lwb, double* coef){
	rest = 0;
	var = variables;
	mtx = new Matrix<double>();
	b = new Vector<double>();
	obj = new Vector<double>();
	sense = new Vector<char>();
	ub = new Vector<double>();
	lb = new Vector<double>();
	for(long i = 0; i < var; i++){
		ub->set(i, upb[i]);
		lb->set(i, lwb[i]);
		obj->set(i, coef[i]);
	}
}

virtual Problem::~Problem(){
	delete rest;
	delete var;
	delete mtx;
	delete b;
	delete obj;
	delete sense;
	delete ub;
	delete lb;
}

bool Problem::addRest(double* coef, long* idx, long pos, char sen, double vb){
	for(long i=0; i< pos; i++){
		mtx[rest][idx[i]] = coef[i];
	}
	sense[rest] = sen;
	b[rest++] = vb;
	return true;
}

bool Problem::changeUpperBound(double vl, long i){
	ub[i] = vl;
	return true;
}

bool Problem::changeLowerBound(double vl, long i){
	lb[i] = vl;
	return true;
}

bool Problem::changeObjValue(double ob, long i){
	obj[i] = ob;
	return true;
}

bool Problem::changeObj(Vector<double> c){
	for(long i = 0; i < var; i++){
		obj[i] = c[i];
	}
	return true;
}

double Problem::value(Vector<double> x){
	double value =0;
	for(long i = 0; i < var; i++){
		value += obj[i]*x[i];
	}
	return value;
}
